package com.bh.springbootjdk17demo.example;

import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.net.URI;
import java.net.URL;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

/**
 * @author sy
 * @version 1.0
 * @description GET
 */
@Slf4j
public class HttpClientExample {

    public static void main(String[] args) {

        //创建一个默认的 HttpClient 实例
        HttpClient client = HttpClient.newHttpClient();
        //创建一个 HttpRequest 实例，指定方法为GET,并设置目标URI
        HttpRequest request = HttpRequest.newBuilder().uri(URI.create("http://localhost:8006/sjzd/msg")).build();

        try {
            HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
            log.info("==response.statusCode()=={}",response.statusCode());
            log.info("==response.body()=={}",response.body());
        } catch (IOException | InterruptedException e) {
            throw new RuntimeException(e);
        }


    }
}
